package cn.le.api;


import cn.le.beans.dto.JobInfoDTO;
import cn.le.beans.dto.JobNameDTO;
import cn.le.beans.vo.ResponseFactory;
import cn.le.beans.vo.ResposeVO;
import cn.le.exception.BizException;
import cn.le.service.JobInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
public class JobApi {

    @Autowired
    private JobInfoService jobInfoService;

    @ApiOperation(value="创建任务", notes="添加任务")
    @RequestMapping(value = "/createJobs")
    public @ResponseBody ResposeVO createJobs(@Valid List<JobInfoDTO> jobInfoDTOs) throws BizException {
        jobInfoService.createJobs(jobInfoDTOs);
        return ResponseFactory.ok("创建任务成功");
    }

    @ApiOperation(value="删除任务", notes="删除任务")
    @RequestMapping(value = "/deleteJobs")
    public @ResponseBody ResposeVO deleteJobs(@Valid List<JobNameDTO> jobNameDTOs) throws BizException {
        jobInfoService.deleteJobs(jobNameDTOs);
        return ResponseFactory.ok("删除任务成功");
    }

    @ApiOperation(value="暂停任务", notes="暂停任务")
    @RequestMapping(value = "/suspendJobs")
    public @ResponseBody ResposeVO suspendJobs(@Valid List<JobNameDTO> jobNameDTOs) throws BizException {
        jobInfoService.suspendJobs(jobNameDTOs);
        return ResponseFactory.ok("暂定任务成功");
    }

    @ApiOperation(value="恢复任务", notes="恢复任务")
    @RequestMapping(value = "/resumeJobs")
    public @ResponseBody ResposeVO resumeJobs(@Valid List<JobNameDTO> jobNameDTOs) throws BizException {
        jobInfoService.resumeJobs(jobNameDTOs);
        return ResponseFactory.ok("恢复任务成功");
    }

    @ApiOperation(value="更新任务", notes="更新任务")
    @RequestMapping(value = "/rescheduleJobs")
    public @ResponseBody ResposeVO rescheduleJobs(@Valid List<JobInfoDTO> jobInfoDTOs) throws BizException {
        jobInfoService.rescheduleJobs(jobInfoDTOs);
        return ResponseFactory.ok("恢复任务成功");
    }








}
